import java.math.BigDecimal;
import java.util.Objects;
import java.util.Random;

public class PartGenerator_Method {
    //随机选择圣遗物部位（花，羽，沙，杯，头）(1,2,3,4,5)
    public int NUMposition() {
        Random r = new Random();
        return r.nextInt(1, 6);
    }

    //部位数字转文字
    public String position(int i) {
        switch (i) {
            case 1 -> {
                return "生之花";
            }
            case 2 -> {
                return "死之羽";
            }
            case 3 -> {
                return "时之沙";
            }
            case 4 -> {
                return "空之杯";
            }
            case 5 -> {
                return "理之冠";
            }
        }
        return "";
    }

    //随机选择主词条
    public String mainTerm(int i) {
        Random r = new Random();
        if (i == 1) {
            return "固定生命值";
        } else if (i == 2) {
            return "固定攻击力";
        } else if (i == 3) {
            int x = r.nextInt(0, 10000);
            if (x >= 0 && x < 2667) {
                return "百分比生命值";
            } else if (x >= 2667 && x < 5334) {
                return "百分比攻击力";
            } else if (x >= 5334 && x < 8000) {
                return "百分比防御力";
            } else if (x >= 8000 && x < 9000) {
                return "元素充能效率";
            } else if (x >= 9000 && x < 10000) {
                return "元素精通";
            }
        } else if (i == 4) {
            int x = r.nextInt(0, 10);
            if (x >= 0 && x < 4) {
                int y = r.nextInt(1, 9);
                switch (y) {
                    case 1:
                        return "火元素伤害加成";
                    case 2:
                        return "雷元素伤害加成";
                    case 3:
                        return "冰元素伤害加成";
                    case 4:
                        return "水元素伤害加成";
                    case 5:
                        return "风元素伤害加成";
                    case 6:
                        return "岩元素伤害加成";
                    case 7:
                        return "草元素伤害加成";
                    case 8:
                        return "物理伤害加成";
                }
            } else if (x >= 4 && x < 10) {
                int y = r.nextInt(0, 60000);
                if (y >= 0 && y < 19175) {
                    return "百分比生命值";
                } else if (y >= 19175 && y < 38350) {
                    return "百分比攻击力";
                } else if (y >= 38350 && y < 57500) {
                    return "百分比防御力";
                } else if (y >= 57500 && y < 60000) {
                    return "元素精通";
                }
            }
        } else if (i == 5) {
            int x = r.nextInt(0, 100);
            if (x >= 0 && x < 22) {
                return "百分比生命值";
            } else if (x >= 22 && x < 44) {
                return "百分比攻击力";
            } else if (x >= 44 && x < 66) {
                return "百分比防御力";
            } else if (x >= 66 && x < 76) {
                return "暴击率";
            } else if (x >= 76 && x < 86) {
                return "暴击伤害";
            } else if (x >= 86 && x < 96) {
                return "治疗加成";
            } else if (x >= 96 && x < 100) {
                return "元素精通";
            }
        }
        return "";
    }

    //随机选择一个副词条(根据部位和主词条)
    public String secondaryTrem(int i, String s) {
        Random r = new Random();
        switch (i) {
            case 1: {
                int x = r.nextInt(0, 10001);
                if (x >= 0 && x <= 1579) {
                    return "固定攻击力";
                } else if (x >= 1579 && x <= 3158) {
                    return "固定防御力";
                } else if (x >= 3158 && x <= 4211) {
                    return "百分比生命值";
                } else if (x >= 4211 && x <= 5264) {
                    return "百分比攻击力";
                } else if (x >= 5264 && x <= 6317) {
                    return "百分比防御力";
                } else if (x >= 6317 && x <= 7370) {
                    return "元素充能效率";
                } else if (x >= 7370 && x <= 8423) {
                    return "元素精通";
                } else if (x >= 8423 && x <= 9212) {
                    return "暴击率";
                } else if (x >= 9212 && x <= 10001) {
                    return "暴击伤害";
                }
            }
            case 2: {
                int x = r.nextInt(0, 10001);
                if (x >= 0 && x <= 1579) {
                    return "固定生命值";
                } else if (x >= 1579 && x <= 3158) {
                    return "固定防御力";
                } else if (x >= 3158 && x <= 4211) {
                    return "百分比生命值";
                } else if (x >= 4211 && x <= 5264) {
                    return "百分比攻击力";
                } else if (x >= 5264 && x <= 6317) {
                    return "百分比防御力";
                } else if (x >= 6317 && x <= 7370) {
                    return "元素充能效率";
                } else if (x >= 7370 && x <= 8423) {
                    return "元素精通";
                } else if (x >= 8423 && x <= 9212) {
                    return "暴击率";
                } else if (x >= 9212 && x <= 10001) {
                    return "暴击伤害";
                }
            }
            case 3: {
                int x = r.nextInt(0, 1100);
                if (x >= 0 && x <= 150) {
                    return "固定生命值";
                } else if (x >= 150 && x <= 300) {
                    return "固定攻击力";
                } else if (x >= 300 && x <= 450) {
                    return "固定防御力";
                } else if (x >= 450 && x <= 550) {
                    return "百分比生命值";
                } else if (x >= 550 && x <= 650) {
                    return "百分比攻击力";
                } else if (x >= 650 && x <= 750) {
                    return "百分比防御力";
                } else if (x >= 750 && x <= 850) {
                    return "元素充能效率";
                } else if (x >= 850 && x <= 950) {
                    return "元素精通";
                } else if (x >= 95 && x <= 1025) {
                    return "暴击率";
                } else if (x >= 1025 && x <= 1100) {
                    return "暴击伤害";
                }
            }
            case 4: {
                if (Objects.equals(s, "百分比生命值") || Objects.equals(s, "百分比攻击力") || Objects.equals(s, "百分比防御力") || Objects.equals(s, "元素精通")) {
                    int x = r.nextInt(0, 1100);
                    if (x >= 0 && x <= 150) {
                        return "固定生命值";
                    } else if (x >= 150 && x <= 300) {
                        return "固定攻击力";
                    } else if (x >= 300 && x <= 450) {
                        return "固定防御力";
                    } else if (x >= 450 && x <= 550) {
                        return "百分比生命值";
                    } else if (x >= 550 && x <= 650) {
                        return "百分比攻击力";
                    } else if (x >= 650 && x <= 750) {
                        return "百分比防御力";
                    } else if (x >= 750 && x <= 850) {
                        return "元素充能效率";
                    } else if (x >= 850 && x <= 950) {
                        return "元素精通";
                    } else if (x >= 95 && x <= 1025) {
                        return "暴击率";
                    } else if (x >= 1025 && x <= 1100) {
                        return "暴击伤害";
                    }
                } else if (Objects.equals(s, "火元素伤害加成") || Objects.equals(s, "雷元素伤害加成") || Objects.equals(s, "冰元素伤害加成") || Objects.equals(s, "水元素伤害加成") || Objects.equals(s, "风元素伤害加成") || Objects.equals(s, "岩元素伤害加成") || s == "草元素伤害加成" || Objects.equals(s, "物理伤害加成")) {
                    int x = r.nextInt(0, 10001);
                    if (x >= 0 && x <= 1364) {
                        return "固定生命值";
                    } else if (x >= 1364 && x <= 2728) {
                        return "固定攻击力";
                    } else if (x >= 2728 && x <= 4092) {
                        return "固定防御力";
                    } else if (x >= 4092 && x <= 5001) {
                        return "百分比生命值";
                    } else if (x >= 5001 && x <= 5910) {
                        return "百分比攻击力";
                    } else if (x >= 5910 && x <= 6819) {
                        return "百分比防御力";
                    } else if (x >= 6819 && x <= 7728) {
                        return "元素充能效率";
                    } else if (x >= 7728 && x <= 8637) {
                        return "元素精通";
                    } else if (x >= 8637 && x <= 9319) {
                        return "暴击率";
                    } else if (x >= 9319 && x <= 10001) {
                        return "暴击伤害";
                    }
                }
            }
            case 5: {
                if (Objects.equals(s, "百分比生命值") || Objects.equals(s, "百分比攻击力") || Objects.equals(s, "百分比防御力") || Objects.equals(s, "元素精通")) {
                    int x = r.nextInt(0, 1100);
                    if (x >= 0 && x <= 150) {
                        return "固定生命值";
                    } else if (x >= 150 && x <= 300) {
                        return "固定攻击力";
                    } else if (x >= 300 && x <= 450) {
                        return "固定防御力";
                    } else if (x >= 450 && x <= 550) {
                        return "百分比生命值";
                    } else if (x >= 550 && x <= 650) {
                        return "百分比攻击力";
                    } else if (x >= 650 && x <= 750) {
                        return "百分比防御力";
                    } else if (x >= 750 && x <= 850) {
                        return "元素充能效率";
                    } else if (x >= 850 && x <= 950) {
                        return "元素精通";
                    } else if (x >= 95 && x <= 1025) {
                        return "暴击率";
                    } else if (x >= 1025 && x <= 1100) {
                        return "暴击伤害";
                    }
                } else if (Objects.equals(s, "治疗加成")) {
                    int x = r.nextInt(0, 10001);
                    if (x >= 0 && x <= 1364) {
                        return "固定生命值";
                    } else if (x >= 1364 && x <= 2728) {
                        return "固定攻击力";
                    } else if (x >= 2728 && x <= 4092) {
                        return "固定防御力";
                    } else if (x >= 4092 && x <= 5001) {
                        return "百分比生命值";
                    } else if (x >= 5001 && x <= 5910) {
                        return "百分比攻击力";
                    } else if (x >= 5910 && x <= 6819) {
                        return "百分比防御力";
                    } else if (x >= 6819 && x <= 7728) {
                        return "元素充能效率";
                    } else if (x >= 7728 && x <= 8637) {
                        return "元素精通";
                    } else if (x >= 8637 && x <= 9319) {
                        return "暴击率";
                    } else if (x >= 9319 && x <= 10001) {
                        return "暴击伤害";
                    }
                } else if (Objects.equals(s, "暴击率") || Objects.equals(s, "暴击伤害")) {
                    int x = r.nextInt(0, 10733);
                    if (x >= 0 && x <= 1463) {
                        return "固定生命值";
                    } else if (x >= 1463 && x <= 2926) {
                        return "固定攻击力";
                    } else if (x >= 2926 && x <= 4389) {
                        return "固定防御力";
                    } else if (x >= 4389 && x <= 5365) {
                        return "百分比生命值";
                    } else if (x >= 5365 && x <= 6341) {
                        return "百分比攻击力";
                    } else if (x >= 6341 && x <= 7317) {
                        return "百分比防御力";
                    } else if (x >= 7317 && x <= 8293) {
                        return "元素充能效率";
                    } else if (x >= 8293 && x <= 9269) {
                        return "元素精通";
                    } else if (x >= 9269 && x <= 10001) {
                        return "暴击率";
                    } else if (x >= 10001 && x <= 10733) {
                        return "暴击伤害";
                    }
                }
            }
        }
        return "";
    }

    //判断主词条和某单个副词条是否相同并纠正
    public String JudgePrimaryAndSecondary(int i, String fir, String sec) {
        while (true) {
            if (Objects.equals(fir, sec)) {
                String s = secondaryTrem(i, fir);
                if (!s.equals(fir)) {
                    return s;
                }
            } else {
                break;
            }
        }
        return sec;
    }

    //生成四个部位的副词条
    public String[] FourSecondaryTrem(int i, String fir) {
        String sec = secondaryTrem(i, fir);//随机选择一个副词条(根据部位和主词条)
        String s1 = JudgePrimaryAndSecondary(i, fir, sec);//判断主词条和某单个副词条是否相同并纠正
        String s2 = null;
        String s3 = null;
        String s4 = null;
        while (true) {
            String xecs2 = secondaryTrem(i, fir);
            s2 = JudgePrimaryAndSecondary(i, fir, xecs2);
            if (Objects.equals(s1, s2)) {
                String xec = secondaryTrem(i, fir);
                s2 = JudgePrimaryAndSecondary(i, fir, xec);
            } else {
                break;
            }
        }
        while (true) {
            String xecs3 = secondaryTrem(i, fir);
            s3 = JudgePrimaryAndSecondary(i, fir, xecs3);
            if (Objects.equals(s1, s3) || Objects.equals(s2, s3)) {
                String xec = secondaryTrem(i, fir);
                s3 = JudgePrimaryAndSecondary(i, fir, xec);
            } else {
                break;
            }
        }
        while (true) {
            String xecs4 = secondaryTrem(i, fir);
            s4 = JudgePrimaryAndSecondary(i, fir, xecs4);
            if (Objects.equals(s1, s4) || Objects.equals(s2, s4) || Objects.equals(s3, s4)) {
                String xec = secondaryTrem(i, fir);
                s4 = JudgePrimaryAndSecondary(i, fir, xec);
            } else {
                break;
            }
        }
        String[] str = {s1, s2, s3, s4};
        return str;
    }

    //根据副词条生成副词条档位
    public double[] SecondaryEntryGear(int i, String fir, String[] str) {
        Random r = new Random();
        double[][] danwei = {{209.13, 239.00, 268.88, 298.75}, {13.62, 15.56, 17.51, 19.45}, {16.2, 18.52, 20.83, 23.15},
                {4.08, 4.66, 5.25, 5.83}, {4.08, 4.66, 5.25, 5.83}, {5.10, 5.83, 6.56, 7.29},
                {4.53, 5.18, 5.83, 6.48}, {16.32, 18.65, 20.98, 23.31}, {2.70, 3.11, 3.50, 3.89}, {5.44, 6.22, 6.99, 7.77}};
        double[] seg = new double[4];
        for (int j = 0; j < 4; j++) {
            if (Objects.equals(str[j], "固定生命值")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[0][x];
            } else if (Objects.equals(str[j], "固定攻击力")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[1][x];
            } else if (Objects.equals(str[j], "固定防御力")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[2][x];
            } else if (Objects.equals(str[j], "百分比生命值")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[3][x];
            } else if (Objects.equals(str[j], "百分比攻击力")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[4][x];
            } else if (Objects.equals(str[j], "百分比防御力")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[5][x];
            } else if (Objects.equals(str[j], "元素充能效率")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[6][x];
            } else if (Objects.equals(str[j], "元素精通")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[7][x];
            } else if (Objects.equals(str[j], "暴击率")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[8][x];
            } else if (Objects.equals(str[j], "暴击伤害")) {
                int x = r.nextInt(0, 4);
                seg[j] = danwei[9][x];
            }
        }
        return seg;
    }

    //升级圣遗物为20级
    public double[] LV20SecondaryEntryGear(String[] str, double[] seg) {
        Random r = new Random();
        int i = r.nextInt(0, 10);
        double[][] danwei = {{209.13, 239.00, 268.88, 298.75}, {13.62, 15.56, 17.51, 19.45}, {16.2, 18.52, 20.83, 23.15},
                {4.08, 4.66, 5.25, 5.83}, {4.08, 4.66, 5.25, 5.83}, {5.10, 5.83, 6.56, 7.29},
                {4.53, 5.18, 5.83, 6.48}, {16.32, 18.65, 20.98, 23.31}, {2.70, 3.11, 3.50, 3.89}, {5.44, 6.22, 6.99, 7.77}};
        if (i >= 0 && i < 8) {
            for (int j = 0; j < 4; j++) {
                int x = r.nextInt(0, 4);
                int y = r.nextInt(0,4);
                if (Objects.equals(str[x], "固定生命值")) {
                    seg[x] = seg[x] + danwei[0][y];
                } else if (Objects.equals(str[x], "固定攻击力")) {
                    seg[x] = seg[x] + danwei[1][y];
                } else if (Objects.equals(str[x], "固定防御力")) {
                    seg[x] = seg[x] + danwei[2][y];
                } else if (Objects.equals(str[x], "百分比生命值")) {
                    seg[x] = seg[x] + danwei[3][y];
                } else if (Objects.equals(str[x], "百分比攻击力")) {
                    seg[x] = seg[x] + danwei[4][y];
                } else if (Objects.equals(str[x], "百分比防御力")) {
                    seg[x] = seg[x] + danwei[5][y];
                } else if (Objects.equals(str[x], "元素充能效率")) {
                    seg[x] = seg[x] + danwei[6][y];
                } else if (Objects.equals(str[x], "元素精通")) {
                    seg[x] = seg[x] + danwei[7][y];
                } else if (Objects.equals(str[x], "暴击率")) {
                    seg[x] = seg[x] + danwei[8][y];
                } else if (Objects.equals(str[x], "暴击伤害")) {
                    seg[x] = seg[x] + danwei[9][y];
                }
            }
        } else {
            for (int j = 0; j < 5; j++) {
                int x = r.nextInt(0, 4);
                int y = r.nextInt(0,4);
                if (Objects.equals(str[x], "固定生命值")) {
                    seg[x] = seg[x] + danwei[0][y];
                } else if (Objects.equals(str[x], "固定攻击力")) {
                    seg[x] = seg[x] + danwei[1][y];
                } else if (Objects.equals(str[x], "固定防御力")) {
                    seg[x] = seg[x] + danwei[2][y];
                } else if (Objects.equals(str[x], "百分比生命值")) {
                    seg[x] = seg[x] + danwei[3][y];
                } else if (Objects.equals(str[x], "百分比攻击力")) {
                    seg[x] = seg[x] + danwei[4][y];
                } else if (Objects.equals(str[x], "百分比防御力")) {
                    seg[x] = seg[x] + danwei[5][y];
                } else if (Objects.equals(str[x], "元素充能效率")) {
                    seg[x] = seg[x] + danwei[6][y];
                } else if (Objects.equals(str[x], "元素精通")) {
                    seg[x] = seg[x] + danwei[7][y];
                } else if (Objects.equals(str[x], "暴击率")) {
                    seg[x] = seg[x] + danwei[8][y];
                } else if (Objects.equals(str[x], "暴击伤害")) {
                    seg[x] = seg[x] + danwei[9][y];
                }
            }
        }
        for (int j = 0; j < 4; j++) {
            BigDecimal bd = new BigDecimal(seg[j]);
            seg[j]=bd.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();//四舍五入到一位小数
        }

        return seg;
    }
}
